package com.wgworkshop.pems.entity.converter;

import com.wgworkshop.pems.common.enums.ClassArrangeStatusEnum;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * 班级安排状态转换器。
 * Created by wlc on 2017/10/11.
 */
@Converter
public class ClassArrangeStatusConverter implements AttributeConverter<ClassArrangeStatusEnum, Integer> {

    @Override
    public Integer convertToDatabaseColumn(ClassArrangeStatusEnum attribute) {
        if (attribute == null) {
            return null;
        }
        return attribute.getCode();
    }

    @Override
    public ClassArrangeStatusEnum convertToEntityAttribute(Integer dbData) {
        if (dbData == null) {
            return null;
        }
        return ClassArrangeStatusEnum.fromCode(dbData);
    }
}
